import axios from "axios";

async function requestMiddleware(request) {
    const options = {
        method: 'POST',
        url: '/api' + request.url,
        headers: {
            token: localStorage.token,
            'content-type': 'application/x-www-form-urlencoded'
        },
        data: request.param,
    };
    try {
        const res = await axios.request(options)
        console.log({
            "请求": request.url,
            "入参": request.param,
            "回参": res.data,
        })
        return res.data
    } catch (e) {
        console.log({
            "请求": request.url,
            "入参": request.param,
            "错误": e,
        })
        return ""
    }
}

export {requestMiddleware};
